{extend name="./template/default/pc/pub/base.html" /}
{block name="seo"}
<title>个人书架-{$site_name}</title>
{/block}
{block name="content"}
<main class="container mt30 mb20 overflow-Show clearfix" style="min-height:750px;">
    {include file="./template/default/pc/pub/uc_menu.html"}
    <article class="article-main pull-right">
        <section class="box-userinfo box ">
            <div class="table-head">
                <ul class="table-tabs">
                    <li>
                        <a class="active">编辑资料</a>
                    </li>
                </ul>
            </div>
            <div class="box-body">
                <form method="post" class="user-info-form mt20" novalidate="novalidate">
                    <div>
                        <label>昵称：</label>
                        <span>
                            <input id="nick_name" type="text" value="{$user.nick_name}">
                        </span>
                    </div>
                    <div>
                        <label>邮箱：</label>
                        <span>
                            <input id="email" type="text" value="{$user.email}">
                        </span>
                    </div>
                    <div class="mt20 text-center">
                        <button id="btnsave" class="save-btn btn" type="button">保存</button>
                    </div>
                </form>
            </div>
        </section>
    </article>
</main>
<script>
    $('#btnsave').click(function () {
        let nickname = filterStr($('#nick_name').val());
        let email = $('#email').val()
        if (nickname.length > 12){
            layer.msg("昵称不能太长");
            return;
        }
        $.post({
            url:'/userinfo',
            data:{nickname: nickname, email:email},
            success:function (res) {
                layer.msg(res.msg);
                setTimeout(function () {
                    location.reload();
                },1000);
            },
            error:function (data) {
                layer.msg(data);
            }
        })
    })

    function filterStr(str)
    {
        var pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~！@#￥……&*（）——|{}【】‘；：”“'。，、？%+_]");
        var specialStr = "";
        for(var i=0;i<str.length;i++)
        {
            specialStr += str.substr(i, 1).replace(pattern, '');
        }
        return specialStr;
    }
</script>
{/block}